﻿using AiBLSmartEdu.Module.SmartStockSense.API.DTOs;
using AiBLSmartEdu.Module.SmartStockSense.API.Services;
using Domain.Entities.Stocks;
using FrameworkCore;
using FrameworkCore.Controllers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AiBLSmartEdu.Module.SmartStockSense.API.Controllers;

/// <summary>
/// 股票查询助手
/// </summary>
[AllowAnonymous]
public class SmartStockSenseController : BaseModuleController
{
    private readonly StockServices _stockServices;

    public SmartStockSenseController(StockServices stockServices)
    {
        _stockServices = stockServices;
    }

    /// <summary>
    /// 查询
    /// </summary>
    /// <param name="keyword">关键字</param>
    /// <returns></returns>
    [HttpGet("Search")]
    public async Task<Result<IEnumerable<StockOutputDto>>> SearchAsync(string keyword)
    {
        var result = await _stockServices.SearchAsync(keyword);
        return await Result<IEnumerable<StockOutputDto>>.SucceedAsync(result);
    }

    /// <summary>
    /// 股票信息
    /// </summary>
    /// <param name="filter">过滤条件</param>
    /// <returns></returns>
    [HttpGet("Information")]
    public async Task<Result<StockInformationDto>> GetStockInformationAsync([FromQuery] StockInformationFilter filter) 
    {
        var result = await _stockServices.GetStockInformationAsync(filter);
        return await Result<StockInformationDto>.SucceedAsync(result);
    }

    /// <summary>
    /// 今天用户查询的股票列表
    /// </summary>
    /// <returns></returns>
    [HttpGet("Today")]
    public async Task<Result<IEnumerable<StockInformation>>> GetTodayUserSearchStockListAsync() 
    {
        var result = await _stockServices.GetTodayUserSearchStockListAsync();
        return await Result<IEnumerable<StockInformation>>.SucceedAsync(result);
    }

    /// <summary>
    /// 预测趋势
    /// </summary>
    /// <param name="stockCode">股票代码</param>
    /// <returns></returns>
    [HttpGet("Predict/Trend/{stockCode}")]
    public async Task<Result<PredictTrendDto>> PredictTrendAsync(string stockCode) 
    {
        var result = await _stockServices.PredictTrendAsync(stockCode);
        return await Result<PredictTrendDto>.SucceedAsync(result);
    }
}